package poem

import (
	"context"
	"fmt"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
	"log"
	"xia/demo/model"
	"xia/demo/mongodb"
)

func SetPoem(poemName string, authorName string, dynasty string, content string) {
	var (
		client     = mongodb.MgoCli()
		err        error
		collection *mongo.Collection
		iResult    *mongo.InsertOneResult
		id         primitive.ObjectID
	)
	collection = client.Database("poem").Collection("tang")

	stock := model.Poem{
		PoemName:   poemName,
		Dynasty:    "唐",
		AuthorName: authorName,
		Content:    content,
	}
	if iResult, err = collection.InsertOne(context.TODO(), stock); err != nil {
		fmt.Print(err)
		return
	}
	id = iResult.InsertedID.(primitive.ObjectID)
	fmt.Println("自增ID", id.Hex())

}
